package com.micro.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author dufen
 * @date 2021-10-29 15:47:29
 * @description
 */
public class ByteUtil {

    public static byte[] getBytes(InputStream inputStream) throws IOException {
        byte[] bytes = new byte[1024];
        int length = 0;
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            while ((length = inputStream.read(bytes)) != -1) {
                bos.write(bytes, 0, length);
                bos.flush();
            }
            return bos.toByteArray();
        }
    }
}
